/*
 * Copyright 2002-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.aop;

/**
 * Filter that restricts matching of a pointcut or introduction to
 * a given set of target classes.
 *
 * <p>Can be used as part of a {@link Pointcut} or for the entire
 * targeting of an {@link IntroductionAdvisor}.
 *
 * <p>Concrete implementations of this interface typically should provide proper
 * implementations of {@link Object#equals(Object)} and {@link Object#hashCode()}
 * in order to allow the filter to be used in caching scenarios &mdash; for
 * example, in proxies generated by CGLIB.
 *
 * @author Rod Johnson
 * @see Pointcut
 * @see MethodMatcher
 */
/*
1. 总结
ClassFilter 是 Spring AOP 框架中的一个核心接口，用于定义类级别的匹配规则。
它与 MethodMatcher 配合使用，共同构成完整的切点（Pointcut）逻辑。
该接口支持函数式编程风格，可以通过 Lambda 表达式实现。
2. 内部成员说明
方法
matches(Class<?> clazz): 判断给定的类是否符合过滤条件。返回 true 表示该类需要应用增强器，返回 false 表示不需要。
字段
TRUE: 静态字段，表示一个匹配所有类的 ClassFilter 实例。
3. 类关系结构
ClassFilter (interface)
│
├── AspectJExpressionPointcut (class)
├── AnnotationClassFilter (class)
├── RootClassFilter (class)
├── TrueClassFilter (class)
├── TypePatternClassFilter (class)
└── ControlFlowPointcut (class)
相关类和接口关系说明
	Pointcut: 包含 ClassFilter 和 MethodMatcher，共同定义了完整的切点逻辑。
	MethodMatcher: 与 ClassFilter 配合使用，先过滤类，再匹配方法。
	IntroductionAdvisor: 使用 ClassFilter 来确定哪些类需要引入新的方法或属性。
4. 使用场景
	在 Spring AOP 中定义切点，判断哪些类需要应用增强器。
	实现基于注解、类型模式或其他条件的类过滤。
	与 MethodMatcher 结合使用，实现复杂的切点逻辑。
	用于控制流切点，根据执行上下文决定是否应用增强器。
5. 实际代码应用示例
// 创建一个基于注解的 ClassFilter
public class AnnotationClassFilter implements ClassFilter {

    private Class<? extends Annotation> annotationType;

    public void setAnnotationType(Class<? extends Annotation> annotationType) {
        this.annotationType = annotationType;
    }

    @Override
    public boolean matches(Class<?> clazz) {
        return clazz.isAnnotationPresent(annotationType);
    }
}

// 使用 ClassFilter 创建 Pointcut
public class MyPointcut implements Pointcut {

    private AnnotationClassFilter classFilter;

    public void setClassFilter(AnnotationClassFilter classFilter) {
        this.classFilter = classFilter;
    }

    @Override
    public ClassFilter getClassFilter() {
        return classFilter;
    }

    @Override
    public MethodMatcher getMethodMatcher() {
        return MethodMatcher.TRUE; // 匹配所有方法
    }
}


 */
@FunctionalInterface
public interface ClassFilter {

	/**
	 * Should the pointcut apply to the given interface or target class?
	 * @param clazz the candidate target class
	 * @return whether the advice should apply to the given target class
	 */
	boolean matches(Class<?> clazz);


	/**
	 * Canonical instance of a ClassFilter that matches all classes.
	 */
	ClassFilter TRUE = TrueClassFilter.INSTANCE;

}
